package com.ftg.learn.day05.ex;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 练习
 * Arrays 数组帮助类
 * Math   数学帮助类
 * @author 布衣
 */
public class Question {

    /**
     * 4.定义一个数组来存储12个学生的成绩{72,89,65,58,87,91,53,82,71,93,76,68}，计算并输出学生的平均成绩。(保留小数点后两位。)
     */
    public double getAvgScore(){
        int[] score = {72,89,65,58,87,91,53,82,71,93,76,68};
        double sum = 0;
        for (int i = 0; i < score.length; i++) {
            sum+=score[i];
        }
        double d = sum/score.length;
        int d1 = (int)(d* 1000);
        int g = d1 % 10 ;
        d1 = d1 / 10 + (g>=5?1:0);
        d = d1 / 100.0;
        return d;
//        return myRound(sum/score.length,2);
    }

    public double myRound(double val,int n){
        int d1 = (int)(val * Math.pow(10,n+1));
        int g = d1 % 10 ;
        d1 = d1 / 10 + (g>=5?1:0);
        return d1 / Math.pow(10,n);
    }

    public static void main(String[] args) {
        Question q = new Question();
        System.out.println(q.getAvgScore());
        System.out.println(Math.abs(-3));

    }

}
